﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DependencyInjection.Bank
{
    public class BankClient
    {
        [ImportMany(typeof(ICard))]
        public IEnumerable<ICard> Service { get; set; }

        public static void Mef()
        {
            BankClient pro = new BankClient();
            pro.Compose();

            if (pro.Service != null)
            {
                foreach (var item in pro.Service)
                {
                    Console.WriteLine(item.GetCountInfo());
                }
            }
            Console.Read();
        }

        private void Compose()
        {
            //var catalog = new DirectoryCatalog("IBookService");
            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            CompositionContainer container = new CompositionContainer(catalog);
            container.ComposeParts(this);
        }
    }
}
